Julia数据科学系列-Bootstrap包

Bootstrap vs permutation

Hack Learn from HERE

  • 都是为了获得统计显著性,但bootstrap用于构建样本均值置信区间,permutation用于构建样本均值的零分布;

  • 被试间比对用permutation, 被试内比对用bootstrap;

Bootstrap.jl

Sampling

Bootstrap核心是有放回地抽样,Bootstrap.jl中定义了常用的抽样函数:

非参数抽样

BasicSampling BalanceSampling ExactSampling AntitheticSampling MaximumEntropySampling

参数抽样

ResidualSampling WildSampling

辅助函数

nrun(bs): 返回样本量 statistic(bs): 返回统计函数 noise(bs::): 返回WildSampling的噪声函数

置信区间

BasicConfInt PercentileConfInt NormalConfInt StudentConfInt BCaConfInt: Bias-coreected and accelerated

用法示例

julia

using Bootstrap
using Statistics # for std func

some_data = randn(100);

n_boot = 1000

# bootstrap
bs1 = bootstrap(std, some_data, BasicSampling(n_boot))
bs2 = bootstrap(std, some_data, BalancedSampling(n_boot))

# misc stats
bias(bs1)
stderror(bs1)

# calc 95% CI
cil = 0.95;
bci1 = confint(bs1, BasicConfInt(cil))
bci2 = confint(bs1, PercentileConfInt(cil))
bci3 = confint(bs1, BCaConfInt(cil))
bci4 = confint(bs1, NormalConfInt(cil))

julia